package dp.gr03.payroll.affiliationTransactions;

import java.util.GregorianCalendar;

import dp.gr03.payroll.affiliations.ServiceCharge;
import dp.gr03.payroll.affiliations.UnionAffiliation;
import dp.gr03.payroll.payrollApplication.Transaction;
import dp.gr03.payroll.payrollDatabase.PayrollDatabase;
import dp.gr03.payroll.payrollDomain.Employee;

public class ServiceChargeTransaction implements Transaction
{
    private int memberId;
    private GregorianCalendar date;
    private double amount;
    protected PayrollDatabase db;
    protected Employee emp;

    public ServiceChargeTransaction(int memberId, GregorianCalendar date, double amount)
    {
        this.memberId = memberId;
        this.date = date;
        this.amount = amount;
        this.db = PayrollDatabase.getInstance();
    }

    @Override
    public void execute()
    {
        emp = db.getUnionMember(memberId);

        if (emp.getAffiliation() instanceof UnionAffiliation)
        {
            ServiceCharge sc = new ServiceCharge(date, amount);
            ((UnionAffiliation) emp.getAffiliation()).addServiceCharge(date, sc);
        }
    }
}
